package com.chao.product.conf.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 广播模式 （发布订阅模式）
 * 比工作模式多了个交换机  先把消息发送到交换机 在由交换机把消息发送到每个队列中
 * 每个绑定的队列都能收到交换机发送的同样的消息, 每个消费者监听自己的队列
 */
@Configuration
public class FanoutConfig {

    @Bean
    public Queue fanoutQueue1(){
        return new Queue("fanout_queue_1");
    }

    @Bean
    public Queue fanoutQueue2(){
        return new Queue("fanout_queue_2");
    }

    @Bean
    public FanoutExchange setFanoutExchange(){
        return new FanoutExchange("fanout_exchange");
    }

    @Bean
    public Binding bindFanoutQueue1(){
        return BindingBuilder.bind(fanoutQueue1()).to(setFanoutExchange());
    }

    @Bean
    public Binding bindFanoutQueue2(){
        return BindingBuilder.bind(fanoutQueue2()).to(setFanoutExchange());
    }
}
